#include <iostream>
#include <set>
#include <vector>
#include <map>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, temp1, temp2, mini = 9999999;
cin >> n >> m;
vector<int> a;
vector<vector<int>> pairs;
vector<int> temp;
temp.push_back(0);
temp.push_back(0);
for (int i = 0; i < n; i++){
cin >> temp1;
a.push_back(temp1);
}
for (int i = 0; i < m; i++){
cin >> temp1 >> temp2;
temp[0] = temp1;
temp[1] = temp2;
pairs.push_back(temp);
}
for (int i = 0; i < m; i++){
map<int, vector<int>> sl;
int summ = a[pairs[i][0] - 1] + a[pairs[i][1] - 1];
for (int j = i + 1; j < m; j++){
if (pairs[j][0] == pairs[i][0]){
sl[pairs[j][1]].push_back(pairs[i][0]);
}
else if (pairs[j][0] == pairs[i][1]){
sl[pairs[j][1]].push_back(pairs[i][1]);
}
else if (pairs[j][1] == pairs[i][0]){
sl[pairs[j][0]].push_back(pairs[i][0]);
}
else if (pairs[j][1] == pairs[i][1]){
sl[pairs[j][0]].push_back(pairs[i][1]);
}
}
for (auto el : sl){
if (el.second.size() == 2){
mini = min(mini, summ + a[el.first - 1]);
}
}
}
if (mini == 9999999){
cout << -1;
} else{
cout << mini;
}
return 0;
}
1551A - Polycarp and Coins | 313A - Ilya and Bank Account |
1469A - Regular Bracket Sequence | 919C - Seat Arrangements |
1634A - Reverse and Concatenate | 1619C - Wrong Addition |
1437A - Marketing Scheme | 1473B - String LCM |
1374A - Required Remainder | 1265E - Beautiful Mirrors |
1296A - Array with Odd Sum | 1385A - Three Pairwise Maximums |
911A - Nearest Minimums | 102B - Sum of Digits |
707A - Brain's Photos | 1331B - Limericks |
305B - Continued Fractions | 1165B - Polycarp Training |
1646C - Factorials and Powers of Two | 596A - Wilbur and Swimming Pool |
1462B - Last Year's Substring | 1608B - Build the Permutation |
1505A - Is it rated - 2 | 169A - Chores |
765A - Neverending competitions | 1303A - Erasing Zeroes |
1005B - Delete from the Left | 94A - Restoring Password |
1529B - Sifid and Strange Subsequences | 1455C - Ping-pong |